package cn.oop.plane;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class Bullet {
    double x, y;
    int speed = 3;
    double degree;
    int width;
    int height;

    public Bullet() {
        degree = Math.random() * Math.PI * 2;
        x = Constant.GAME_WIDTH / 2;
        y = Constant.GAME_HEIGHT / 2;
        width = 10;
        height = 10;
    }

    public Rectangle getRect() {
        return new Rectangle((int) x, (int) y, width, height);

    }

    public void draw(Graphics g) {
        Color c = g.getColor();
        g.setColor(Color.red);

        g.fillOval((int) x, (int) y, width, height);
        x += speed * Math.cos(degree);
        y += speed * Math.sin(degree);

        if (y > Constant.GAME_HEIGHT || y < 0) {
            degree = -degree;
        }
        if (x > Constant.GAME_WIDTH || x < 0) {
            degree = Math.PI - degree;
        }
        g.setColor(c);
    }
}
